package com.spider.demo7tcp4;

import java.io.DataInputStream;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;


public class ServerDemo2 {
    public static void main(String[] args) throws Exception {
        System.out.println("服务端启动了...");
        System.out.println("本机的ip地址是："+ InetAddress.getLocalHost().getHostAddress());
        //目标：BS架构的原理理解
        //1.创建一个服务器Socket对象，绑定监听端口
        ServerSocket ss = new ServerSocket(8080);
        //创建线程池：
        ExecutorService pool = new ThreadPoolExecutor(5,5,10, TimeUnit.SECONDS, new ArrayBlockingQueue<>(100),new ThreadPoolExecutor.AbortPolicy());
        while (true) {
            Socket socket = ss.accept();
            System.out.println("一个客户端上线："+socket.getInetAddress().getHostAddress());
            pool.execute(new ServerReader( socket));
        }
    }
}
